<template>
  <basic-panel>
    <template #header>
      搜索结果
    </template>
    <template>
      <topics-list :topics="topics"/>
      <pagination :totalTopics="totalTopics"/>
    </template>
  </basic-panel>
</template>
<script>
  import BasicPanel from '@components/common/panel/BasicPanel'
  import TopicsList from '@components/common/TopicsList'
  import Pagination from '@components/common/Pagination'
  export default {
    name: 'search-panel',
    components: {BasicPanel, TopicsList, Pagination},
    data() {
      return {
        topics: [],
        totalTopics: 0,
        searchStr: null,
      }
    },
    methods: {
      getTopics(str) {
        this.$axios.getData.searchTopics(str)
          .then(res => {
            if(res.data.code === 0) {
              this.topics = res.data.data.thread === null ? [] : res.data.data.thread
              this.totalTopics = res.data.data.total
            }
            else {
              // console.log('找不到文章')
            }
          })
      }
    },
    created() {
      this.searchStr = this.$route.params.query
      this.getTopics(this.searchStr)
    },
    beforeRouteUpdate(to, from, next) {
      this.getTopics(to.params.query)
      next()
    }
  }
</script>

<style scoped>
  
</style>
